import React from "react";
import { Table } from "antd";
import { useTranslation } from "react-i18next";

export default function UserTable(props) {
  const { user_list,  tableHeight } = props;
  const { t } = useTranslation();

  // 国内国外判断
  const session_company = sessionStorage.getItem("company");
  const columns = [
    {
      dataIndex: "idx",
      align: "center",
      width: 40,
      render: (_, record, index) => <>{index + 1}</>,
    },
    {
      title: t("system_manager.login_account"),
      dataIndex: "username",
      align: "center",
    },
    {
      title: t("system_manager.name"),
      align: "center",
      render: (_, record) => (
        <>
          <div>{record.name}</div>
          <div>{record.last_name}</div>
        </>
      ),
    },
    {
      title: (ReactNode) => {
        return session_company === "mg" ? "Email" : "手机号";
      },
      align: "center",
      render: (_, record) => (
        <>
          {session_company === "mg"
            ? `***${record.email.substring(7)}`
            : `***${record.tel.substring(7)}`}
        </>
      ),
    },
    {
      title: t("system_manager.last_login_time"),
      dataIndex: "utime",
      align: "center",
    },
  ];
  return (
    <>
      <Table
        dataSource={user_list}
        size="small"
        bordered
        columns={columns}
        rowKey="username"
        virtual
        scroll={{
          y: tableHeight,
        }}
        pagination={false}
      />
    </>
  );
}
